﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Text;
using Fcl.DataWork;
using Fcl.WSOP;
namespace Db
{
    /// <summary>
    /// App 的摘要说明
    /// </summary>
    public class App
    {
        
        public static sqldbop ws;
        private static string _whseid;
        private static string _userId;
        private static string _userName;
        private static string _customer_code;
        /// <summary>
        /// 客户代码
        /// </summary>
        public string customer_code
        {
            get
            { return _customer_code; }
            set
            { _customer_code = value; }
        }
        /// <summary>
        /// 仓库代码
        /// </summary>
        public string whseid
        {
            get
            { return _whseid; }
            set
            { _whseid = value; }
        }
        /// <summary>
        /// 用户ID
        /// </summary>
        public static string userId
        {
            get { return _userId; }
            set { _userId = value; }
        }
        /// <summary>
        /// 用户名称
        /// </summary>
        public static string userName
        {
            get { return _userName; }
            set { _userName = value; }
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public static DataSet GetListByPage(string tabName,string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T."+orderby);
            }
            else
            {
                strSql.Append("order by T. desc");
            }
            strSql.Append(")AS Row, T.*  from "+tabName+" T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return ws.GetDataSet(strSql.ToString(),"",false,"");
        }
        /// <summary>
        /// 调用中、英两种DatePicker JS
        /// </summary>
        /// <param name="page">Page参数</param>
        /// <param name="jsFile">JS文件名</param>
        public static void setDatePicker(Page page,string jsFile)
        {
            HtmlGenericControl autoCompleteScript = new HtmlGenericControl("script");
            autoCompleteScript.Attributes.Add("type", "text/javascript");
            autoCompleteScript.Attributes.Add("src", "../Common/My97DatePicker/" + jsFile);
            page.Header.Controls.Add(autoCompleteScript);
        }
    }
}
